// 1. 引入 express
const express = require('express')

// 2. 引入 cors
const cors = require('cors')

// 3. 引入 monngoose
const mongoose = require('mongoose')

// 4. 引入路由模块
const indexRouter = require('./routes/index')
const userRouter = require('./routes/users')
const fileRouter = require('./routes/file')
const patientRouter = require('./userData/user')

// 接诊病人数量信息
const echNum = require('./doctorData/Echarts/numberH')

// app端 医生信息
const docRouter = require('./doctorData/index')
const serRouter = require('./serviceData/index')

// mock数据
const mock = require('./Echarts/mock')

// 全部疫苗
const hpvRouter = require('./datas/data')

// 7天
const sevenRouter = require('./sevenHours/senvenHours')

// 15天
const fiveRouter = require('./five/five')

// 24小时
const hours = require('./hours/hours')

// 药品
const medical = require('./medical/medical')

// 5. 连接数据库
mongoose.connect('mongodb://localhost:27017/doctor')
// mongoose.connect('mongodb://localhost:27017/user')

// 6. 创建应用
const app = express()

// 7. 解决跨域问题
app.use(cors())
// 8. 处理 POST 请求
app.use(express.json())  // 用于处理 application/json 格式的数据
app.use(express.urlencoded({ extended: true }))

// 9. 静态资源处理
app.use(express.static('public'))

// 10. 使用路由中间件
// indexs表示会话跟踪
app.use('/api/v1/doctor/sessions', indexRouter)

app.use('/api/doctor/upload', fileRouter)

app.use('/api/v1/doctor/users', userRouter)

app.use(patientRouter)

// app端医生信息
app.use(docRouter)
app.use(serRouter)

// hpv
app.use(hpvRouter)
// 7天
app.use(sevenRouter)
// 15天
app.use(fiveRouter)
// 24小时
app.use(hours)
// 药品
app.use(medical)

// 服务站接诊数量
app.use(echNum)

app.use(mock)

// 11. 监听接口
app.listen(10777, () => {
    console.log('Server lisrening running at http://localhost:10777')
})